#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100005;
typedef long long ll;
const ll inf = 1LL << 60;
ll p[MAXN];

struct brick{
	long long m, d;
}b[MAXN];

bool cmp(brick x, brick y){
	return x.d <= y.d;
}

int main(){
	int t, N, T;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &N);
		for(int i=0;i<N;i++){
			scanf("%lld %lld", &b[i].m, &b[i].d);
		}
		scanf("%d", &T);
		p[0] = 0;
		for(int i=1;i<=T;i++){
			scanf("%lld", &p[i]);
		}
		p[T+1] = inf;
		
		sort(p+1, p+1+T);
		sort(b, b+N, cmp);
		
		long long cntb = 0, score = 0, F = 1;
		for(int i=1;i<=T;i++){
			int tem = p[i] - p[i-1];
			while(tem > 0){
				if(tem >= b[cntb].m){
					tem -= b[cntb].m;
					score += b[cntb].m * b[cntb].d * F;
					b[cntb].m = 0;
					cntb++;
					if(cntb >= N){
						break;
					}
				}else{
					b[cntb].m -= tem;
					score += tem * b[cntb].d * F;
					tem = 0;
				}
			}
			F++;
			if(cntb >= N){
				break;
			}
		}
		while(cntb < N){
			score += b[cntb].m * b[cntb].d * F;
			b[cntb].m = 0;
			cntb++;
		}
		printf("%lld\n", score);
	}
	return 0;
}
